home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
games2
/
rotise12.zip
/
ROSTER.C
< prev
next >
Wrap
Text File
|
1993-03-28
|
9KB
|
382 lines
/* roster.c
Jonathan Arnold 1991
Commands to create leagues and rosters. These function are usually
only run before the first interval.
For instance:
league - Describe league
team - describe a team
create - Create a new player in player database
add - add a player to a rotisserie team
minors - add a player to rotisserie team's minors
*/
#include <string.h>
#ifdef __TURBOC__
#include <alloc.h>
#else
#include <malloc.h>
#endif
#include "rotise.h"
#include "rdb.h"
/* External data referenced */
extern BOOL Verbose; /* rotise.c */
extern int Cmd;
extern int InputLine;
extern char *InputFilename;
extern CMDLIST CmdTable[]; /* cmdtable.c */
/* External routines used */
/* NONE */
/* Local data publicly available */
RDB_TEAM *RotoTeams = NULL; /* First team in list */
int RotoTeamCnt = 0; /* How many teams in League */
RDB_TEAM *LastTeam = NULL; /* Current end of list */
char LeagueName[MAX_LEAGUESIZE]; /* Name of league */
/* Local routine prototypes */
/* NONE */
/* Private data */
/* NONE */
/*
BOOL league( int tokcnt, char *tokens[] )
Describe the league in one line of 80 characters or less. Can be
anything you want.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL league ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
int argcnt;
if ( tokcnt < 2 )
ARGCNT_ERR();
for ( argcnt = 1; argcnt < tokcnt; argcnt++ )
{ /* add to league name */
if ( (strlen(LeagueName) + strlen(tokens[argcnt])) > MAX_LEAGUESIZE )
{ /* too big */
fprintf( stderr, "!WARNING!League name truncated.\n" );
return TRUE;
}
strcat( LeagueName, " " );
strcat( LeagueName, tokens[argcnt] );
}
return TRUE;
}
/*
BOOL team( int tokcnt, char *tokens[] )
Describe a team. Give it a Rotisserie Keyword and a name.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL team ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
int argcnt;
if ( tokcnt < 3 )
ARGCNT_ERR();
if ( RotoTeams == NULL )
{ /* First one */
RotoTeams = (RDB_TEAM *)calloc( 1, sizeof( RDB_TEAM ) );
LastTeam = RotoTeams;
}
else
{ /* add to end of list */
LastTeam->next = (RDB_TEAM *)calloc( 1, sizeof( RDB_TEAM ));
LastTeam = LastTeam->next;
}
if ( LastTeam == NULL )
{ /* problems */
fprintf( stderr, "Ran out of memory.\n" );
return FALSE;
}
/* One more team */
RotoTeamCnt++;
/* get key */
strncpy( LastTeam->key, tokens[1], sizeof( LastTeam->key )-1 );
/* now get the team name */
for ( argcnt = 2; argcnt < tokcnt; argcnt++ )
{ /* add strings to end of name */
if ( argcnt != 2 )
strcat( LastTeam->name, " " );
if ( (strlen( LastTeam->name ) + strlen( tokens[argcnt] )) > MAX_TEAMSIZE )
{ /* too long a string */
break;
}
strcat( LastTeam->name, tokens[argcnt] );
}
return TRUE;
}
/*
BOOL owner( int tokcnt, char *tokens[] )
Describe a team's owner(s).
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL owner ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
RDB_TEAM *rteam;
int argcnt;
if ( tokcnt < 3 )
ARGCNT_ERR();
VERBOSE( 5, "\Owner of %s", tokens[1] );
VERBOSE( 5, " is %s.\n", tokens[2] );
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[1] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Owner - Team Keyword Not Found: ", tokens[1] );
return TRUE;
}
/* now get the owner name */
for ( argcnt = 2; argcnt < tokcnt; argcnt++ )
{ /* add strings to end of name */
if ( argcnt != 2 )
{ /* tack on a space */
strcat( rteam->owner, " " );
}
if ( (strlen( rteam->owner ) + strlen( tokens[argcnt] )) > MAX_TEAMSIZE )
{ /* too long a string */
break;
}
strcat( rteam->owner, tokens[argcnt] );
}
return TRUE;
}
/*
BOOL add( int tokcnt, char *tokens[] )
Add player to a rotisserie teams's roster. Creates the player
entry in the player database if necessary.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL add ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
RDB_TEAM *rteam;
RDB_PLAYER *rplayer, *wplayer;
PDB_PNAME nameblk;
VERBOSE( 5, "\tAdding to %s", tokens[1] );
VERBOSE( 5, " %s.\n", tokens[2] );
for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
{ /* find the team */
if ( strcmp( rteam->key, tokens[1] ) == 0 )
break;
}
if ( rteam == NULL )
{ /* couldn't find it */
rdb_error( "Add - Team Keyword Not Found: ", tokens[1] );
return TRUE;
}
rplayer = (RDB_PLAYER *)calloc( 1, sizeof( RDB_PLAYER ) );
if ( rplayer == NULL )
{ /* couldn't get memory */
fprintf( stderr, "Unable to get memory.\n" );
return FALSE;
}
if ( rdb_add_player( rplayer, tokcnt, tokens ) == FALSE )
{ /* had problems, free it up */
free( rplayer );
}
else
{ /* worked just fine, add to list */
if ( rteam->players == NULL )
{ /* first player */
rteam->players = rplayer;
}
else
{ /* find last one */
for ( wplayer = rteam->players; wplayer->next != NULL; wplayer = wplayer->next )
{ /* skip through the list */
}
wplayer->next = rplayer;
}
rplayer->start = 1;
rplayer->end = 1;
rteam->money_spent += rplayer->salary;
/* Now make sure the player is in the player database. */
strcpy( &nameblk.pn_lname[0], &rplayer->pname.pn_lname[0] );
strcpy( &nameblk.pn_fname[0], &rplayer->pname.pn_fname[0] );
strcpy( &nameblk.pn_team[0], &rplayer->pname.pn_team[0] );
nameblk.batter = ( slot_get( rplayer->slot )->slot[0] != 'P' );
if ( !pdb_create_player( &nameblk ) )
{ /* Couldn't create */
fprintf( stderr, "add: Can't create player data for %s, %s\n",
&nameblk.pn_lname[0], &nameblk.pn_fname[0] );
}
else
{ /* Mark the guy not free */
pdb_status( &nameblk, "", "", PLAYER_CLAIMED, 1 );
}
}
return TRUE;
}
/*
BOOL create( int tokcnt, char *tokens[] )
Create a player. This is used when a player is needed but has
not yet been registered to the player database via stat files.
E.g., claiming somebody who hasn't yet played.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
#define ARG_CRE_PK1 1 /* Player key, last name */
#define ARG_CRE_PK2 2 /* Player key, first name/initial */
#define ARG_CRE_POS 3 /* Position list */
BOOL create ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
int i;
UWORD m;
UWORD posmask;
PDB_PNAME nameblk;
PDATA *pdata;
VERBOSE( 5, "\tCreating player %s", tokens[ARG_CRE_PK1] );
VERBOSE( 5, " %s.\n", tokens[ARG_CRE_PK2] );
/* Make sure there are enough tokens */
if ( tokcnt < ARG_CRE_PK2 )
ARGCNT_ERR();
/* Make position eligibility mask from position args */
for( posmask = 0, i = ARG_CRE_POS; i < tokcnt; ++i )
{
m = pos_to_mask( tokens[i] );
if ( m == 0 )
{ /* Position not recognized */
rdb_error( "Unknown position: ", tokens[i] );
}
else
posmask |= m;
}
/* Build player block and create the player */
strcpy( &nameblk.pn_lname[0], strupr(tokens[ARG_CRE_PK1]) );
strcpy( &nameblk.pn_fname[0], strupr(tokens[ARG_CRE_PK2]) );
strcpy( &nameblk.pn_team[0], "" );
nameblk.batter = ( ( posmask & POS_P ) == 0 );
if ( !pdb_create_player( &nameblk ) )
{ /* Can't make 'im */
rdb_error( "Can't create ", &nameblk.pn_lname[0] );
}
pdata = pdb_pdata( tokens[ARG_CRE_PK1], tokens[ARG_CRE_PK2], TRUE );
if ( pdata == NULL )
{ /* try to find as pitcher */
pdata = pdb_pdata( tokens[ARG_CRE_PK1], tokens[ARG_CRE_PK2], FALSE );
}
if ( pdata != NULL )
{ /* shouldn't happen - set zorch to be FREE agent */
pdata->zorch = PLAYER_FREE;
}
/* Set position mask, honoring any old value. */
pdb_getpos( &nameblk, &m );
pdb_setpos( &nameblk, m | posmask );
return TRUE;
}
/*
BOOL minors( int tokcnt, char *tokens[] )
Add a player to a rotisserie team's minor league reserve.
ACCEPTS:
int tokcnt - how many tokens on this line
char *tokens[] - array pointing to each token
RETURNS:
BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
*/
BOOL minors ARGLIST( (tokcnt, tokens) )
NFARG( int tokcnt )
FARG( char *tokens[] )
{
return TRUE;
}